#include "PrecompiledHeader.h"
#include "RenderableVao.h"

/*--------------------------------------------------------------------------*/

RenderableVao::RenderableVao(const NodeCreation& nc) :
	IRenderableObject(nc)
{
	this->m_lqVao = ROpenGL::GetCubeVao();
	this->m_hqVao = ROpenGL::GetCubeVao();

	/*--------------------------------------------------------------------------*/

	RenderTaskDesc desc;
	desc.m_material = g_Material->GetMaterial("mat_default");
	desc.m_argument = 10;
	desc.m_flags = ERenderTaskFlag::SortByDist;
	desc.m_priority = 0;
	desc.m_object = this;

	this->AddRenderTask(desc);
}

/*--------------------------------------------------------------------------*/

RenderableVao::~RenderableVao()
{

}

/*--------------------------------------------------------------------------*/

GLVertexArray* RenderableVao::GetLowQualityVao()
{
	return this->m_lqVao;
}

/*--------------------------------------------------------------------------*/

void RenderableVao::SetLowQualityVao(GLVertexArray* nvao)
{
	this->m_lqVao = nvao;
}

/*--------------------------------------------------------------------------*/

GLVertexArray* RenderableVao::GetHighQualityVao()
{
	return this->m_hqVao;
}

/*--------------------------------------------------------------------------*/

void RenderableVao::SetHighQualityVao(GLVertexArray* nvao)
{
	this->m_hqVao = nvao;
}

/*--------------------------------------------------------------------------*/

void RenderableVao::RenderableHelper(const uint i, ERenderQuality::Type quality, uint pendingInstances)
{
	if (i != 10)
	{
		return;
	}

	if (quality == ERenderQuality::HighQuality && this->m_hqVao != NULL)
	{
#ifdef VL_RENDER_STATISTICS
		g_Hud->GetStatisticsManager()->IncrementStatistic("RenderableVao/HighQuality");
#endif
		ROpenGL::BindVertexArray(this->m_hqVao);
		ROpenGL::DrawVertexArray(pendingInstances);
	}
	else if (quality == ERenderQuality::LowQuality && this->m_lqVao != NULL)
	{
#ifdef VL_RENDER_STATISTICS
		g_Hud->GetStatisticsManager()->IncrementStatistic("RenderableVao/LowQuality");
#endif
		ROpenGL::BindVertexArray(this->m_lqVao);
		ROpenGL::DrawVertexArray(pendingInstances);
	}
}

/*--------------------------------------------------------------------------*/

void RenderableVao::RenderableBinder(uint treeCalcFlags)
{
#ifdef VL_RENDER_STATISTICS
	g_Hud->GetStatisticsManager()->IncrementStatistic("RenderableVao");
#endif
	this->BindRenderTask(this->GetSceneInstance()->GetRenderPhase(), 10);
}

/*--------------------------------------------------------------------------*/